package com.wl.dzt.sys.fmk;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.Map;


/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/2/002
 * @description freemarker 封装
 */
public class Fmkr {
    public static Configuration cfg = null;

    /**
     * 根据路径 和数据栈 以及文件输出路径
     *
     * @param path       路径
     * @param data       数据
     * @param toFileName 文件输入路径
     */
    public static void builder(String path, Map<String, Object> data, String toFileName) {
        OutputStreamWriter osw;
        try {
            osw = new OutputStreamWriter(new FileOutputStream(toFileName, false), "UTF-8");
            Template template = cfg.getTemplate(path);
            template.process(data, osw);
            osw.flush();
            osw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
